#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include<QGraphicsScene>
#include<QGraphicsPixmapItem>
#include<QTimer>
#include<QKeyEvent>
#include<QStackedWidget>
#include<QPushButton>
#include<QLabel>
#include"gameconfig.h"
QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; }
QT_END_NAMESPACE

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    MainWindow(QWidget *parent = nullptr);
    void keyPressEvent(QKeyEvent *event)override;
    ~MainWindow();
private slots:
    void showSkillSelection();
    void showLevelSelection();
    void startGame();
    void startGameCore();
    void updateGame();
    void spawnObstacle();
    void useSkill();
    void spawncoin();
    void handleCoinCollision(QGraphicsItem *coin);
private:
    //背景相关成员
    QGraphicsPixmapItem *gameBackground;  //游戏背景
    QLabel *mainMenuBgLabel;    //主菜单背景

    //新增启动动画面成员
    QWidget *splashScreen;
    QLabel *splashLabel;
    QMovie *splashMovie;
    QTimer *splashTimer;

    void creatMainMenu();
    void createSkillMenu();
    void createLevelMenu();
    void showPauseMenu();
    void initGameScene();
    void checkCollision();
    void gameOver(bool success);


    //界面管理
    QStackedWidget *stackWidget;
    QWidget *mainMenu;
    QWidget *skillMenu;
    QWidget *levelMenu;
    QGraphicsScene *gameScene;
    QGraphicsView *gameView;

    //游戏元素
    QGraphicsPixmapItem *player;
    QTimer *gameTimer;
    QTimer *obstacleTimer;
    QTimer *countdownTimer;
    QTimer *coinTimer;
    //游戏状态
    Skill selectedSkill;
    Level currentLevel;
    int remainingTime;
    int jumpCount = 0;
    bool isJumping = false;
    bool gameRunning = false;
    QList<Skill>availableSkills;
    QList<Level>gameLevels;
    QGraphicsTextItem *timeDisplay;
    QGraphicsTextItem *skillDisplay;
    // 新增成员变量
    GameLevel gameLevel;
    int m_elapsedTime = 0;      // 用于无尽模式计时
    int m_baseObstacleInterval; // 保存初始障碍间
    QGraphicsTextItem* m_endlessScore = nullptr;



    //新增成员
    QGraphicsTextItem *scoreDispaly;
    int currengScore = 0;
    QGraphicsPixmapItem *powerUp = nullptr;

    void spawnPowerUp();
    void handlePowerUpCollision();

    QTimer *m_powerUpTimer;
    int m_powerUpInterval;
    QList<QGraphicsItem*>m_powerUps;

    Ui::MainWindow *ui;
};
#endif // MAINWINDOW_H
